using System;
using System.Threading;

namespace CoreLib
{
    /// <summary>
    /// An object that will wait until <see cref="Release"/>d when disposed.
    /// </summary>
    public class Waiter : IDisposable
    {
        private AutoResetEvent _waiter;

        public Waiter()
        {
            _waiter = new AutoResetEvent( true );
            _waiter.Reset();
        }

        public void Wait()
        {
            _waiter.WaitOne( 5000 );
        }

        public void Release()
        {
            _waiter.Set();
        }

        public void Dispose()
        {
            Wait();
        }
    }
}